package dp;

/**
 * 221. 最大正方形
 */
public class P221 {

    public int maximalSquare(char[][] matrix) {
        int h = matrix.length;
        int w = matrix[0].length;
        int i = 0;
        for (i = 1; i <= Math.min(h, w); i++) {
            if (!checkValid(matrix, i)) {
                break;
            }
        }
        return (i - 1) * (i - 1);
    }

    private boolean checkValid(char[][] matrix, int size) {
        int h = matrix.length;
        int w = matrix[0].length;
        for (int i = 0; i <= w - size; i++) {
            a:
            for (int j = 0; j <= h - size; j++) {
                for (int x = 0; x < size; x++) {
                    for (int y = 0; y < size; y++) {
                        int pos_w = i + x;
                        int pos_h = j + y;
                        if (matrix[pos_h][pos_w] == '0') {
                            continue a;
                        }
                    }
                }
                return true;
            }
        }

        return false;
    }


    private int dp(char[][] matrix) {


        return 0;
    }


    public static void main(String[] args) {
        /*char[][] matrix = new char[][]{
                {'1', '0', '1', '0', '0'},
                {'1', '0', '1', '1', '1'},
                {'1', '1', '1', '1', '1'},
                {'1', '0', '0', '1', '0'}
        };*/
        char[][] matrix = new char[][]{
                {'0', '1'}
        };
        int size = new P221().maximalSquare(matrix);
        System.out.println(size);
    }

}
